home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / test / substring.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  105 lines

  1. /* Test class SubString
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    substring.c,v $
  26.  * Revision 3.0  90/05/20  00:30:04  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/substring.c,v 3.0 90/05/20 00:30:04 kgorlen Rel $";
  31.  
  32. #include "String.h"
  33.  
  34. main()
  35. {
  36.     cout << "\nTest Class SubString" << endl;
  37.     String s4 = "0123456789";
  38.     String s;
  39. cout << "void SubString::operator=(const String&): ";
  40.     s = s4;
  41.     s(1,3) = String("xxx");
  42.     cout << s << endl;            // "0xxx456789"
  43. cout << "void SubString::operator=(const SubString&): ";
  44.     s = s4;
  45.     s(1,3) = String('x',10)(0,3);
  46.     cout << s << endl;            // "0xxx456789"
  47. cout << "void SubString::operator=(const char*): ";
  48.     s = s4;
  49.     s(1,3) = "xxx";
  50.     cout << s << endl;            // "0xxx456789"
  51.     s = s4;
  52.     s(10,0) = "";
  53.     cout << s << endl;            // "0123456789"
  54. cout << "void replace(const char* st, unsigned ln):" << endl;
  55.     s = s4; s.reSize(11);
  56.     s(1,0) = "*";
  57.     cout << s << endl;            // "0*123456789"
  58.     s = s4; s.reSize(11);
  59.     s(0,0) = "*";
  60.     cout << s << endl;            // "*0123456789"
  61.     s = s4; s.reSize(11);
  62.     s(10,0) = "*";
  63.     cout << s << endl;            // "0123456789*"
  64.     s = s4; s.reSize(0);
  65.     s(1,1) = "";
  66.     cout << s << endl;            // "023456789"
  67.     s = s4; s.reSize(0);
  68.     s(0,1) = "";
  69.     cout << s << endl;            // "123456789"
  70.     s = s4; s.reSize(0);
  71.     s(9,1) = "";
  72.     cout << s << endl;            // "012345678"
  73.     s = s4; s.reSize(0);
  74.     s(10,0) = "";
  75.     cout << s << endl;            // "0123456789"
  76.     s = s4; s.reSize(0);
  77.     s(2,0) = s(0,1);
  78.     cout << s << endl;            // "01023456789"
  79.     s = s4; s.reSize(0);
  80.     s(0,0) = s(0,1);
  81.     cout << s << endl;            // "00123456789"
  82.     s = s4; s.reSize(0);
  83.     s(0,1) = s(9,0);
  84.     cout << s << endl;            // "123456789"
  85.     s = s4; s.reSize(0);
  86.     s(0,1) = s(0,2);
  87.     cout << s << endl;            // "01123456789"
  88. cout << "bool SubString::operator<(const String&): ";
  89.     cout << (s4(0,9) < s4) << endl;        // 1
  90. cout << "bool SubString::operator<(const SubString& ss): ";
  91.     cout << (s4(0,8) < s4(0,9)) << endl;    // 1
  92. cout << "bool SubString::operator<(const char* cs): ";
  93.     cout << (s4(0,9) < "01234567890") << endl;    // 1
  94. cout << "friend bool operator<(const char* cs, const SubString& ss): ";
  95.     cout << ("01234567" < s4(0,9)) << endl;    // 1
  96. cout << "String SubString::operator&(const String&): ";
  97.     cout << (s4(0,1) & s4) << endl;        // "00123456789"
  98. cout << "String SubString::operator&(const SubString&): ";
  99.     cout << (s4(0,2) & s4(8,2)) << endl;    // "0189"
  100. cout << "String SubString::operator&(const char*): ";
  101.     cout << (s4(0,2) & "*") << endl;    // "01*"
  102. cout << "friend String operator&(const char*, const SubString&): ";
  103.     cout << ("*" & s4(0,2)) << endl;    // "*01"
  104. }
  105.